* This do-file makes "Table B.1. Summary statistics"
* File written by Kazuma Takakura kazuma.arukakat@gmail.com (University of Tokyo)
* Last updated on April 27, 2024

set more off
use "$path_data/fninvest_experience.dta", clear

replace age_old = . if age_missing == 1
replace numhh = . if numhh == 0
replace risk00_1std = . if risk00_missing == 1


gen agetrim = age_old if age_old>=40 & age_old <= 70

foreach j in n mean sd min max {
tabstat fn8500 fn0010 houseland house land_all land_inherit risk00_1std risk10_1std success85 success00 hyper00 hyper10 highdisc00 highdisc10 high_edu age_old agetrim numhh riceland , stat(`j') save
matrix list r(StatTotal)
matrix `j'_stat = r(StatTotal)
}


tempname hh2
file open `hh2' using "$path_tex/summary_stat.tex", write replace
file write `hh2' "" _newline
file write `hh2' "% Author: Kazuma Takakura" _newline
file write `hh2' "% Date: `c(current_date)'" _newline
file write `hh2' "% Time: `c(current_time)'" _newline
file write `hh2' "" _newline


file write `hh2' "\begin{table}[t!]\footnotesize" _newline
file write `hh2' "  \centering" _newline
file write `hh2' "  \caption{Summary Statistics}" _newline
file write `hh2' "\label{tab:sumstat}" _newline
file write `hh2' "\scalebox{0.9}{" _newline
file write `hh2' "\begin{threeparttable}" _newline

file write `hh2' "\begin{tabular}{lccccc}\toprule" _newline


file write `hh2' "  & Mean & SD & Min & Max & Observations   \\\midrule\midrule" _newline
file write `hh2' "  FN adoption in 1985-2000 (dummy)   & " %04.3f (mean_stat[1,1]) " &  " %04.3f (sd_stat[1,1]) " & "  (min_stat[1,1]) " & " (max_stat[1,1]) " & " (n_stat[1,1]) " \\" _newline
file write `hh2' "  FN adoption in 2000-2010 (dummy)   & " %04.3f (mean_stat[1,2]) " &  " %04.3f (sd_stat[1,2]) " & " (min_stat[1,2]) " & " (max_stat[1,2]) " & " (n_stat[1,2]) " \\" _newline

file write `hh2' "  Displacement (dummy) & " %04.3f (mean_stat[1,3]) " &  " %04.3f (sd_stat[1,3]) " & " (min_stat[1,3]) " & " (max_stat[1,3]) " & " (n_stat[1,3]) " \\" _newline
file write `hh2' "  Home loss (dummy) & " %04.3f (mean_stat[1,4]) " &  " %04.3f (sd_stat[1,4]) " & " (min_stat[1,4]) " & " (max_stat[1,4]) " & " (n_stat[1,4]) " \\" _newline
file write `hh2' "  Land loss (dummy) & " %04.3f (mean_stat[1,5]) " &  " %04.3f (sd_stat[1,5]) " & " (min_stat[1,5]) " & " (max_stat[1,5]) " & " (n_stat[1,5]) " \\" _newline
file write `hh2' "  Land owner (dummy) & " %04.3f (mean_stat[1,6]) " &  " %04.3f (sd_stat[1,6]) " & " (min_stat[1,6]) " & " (max_stat[1,6]) " & " (n_stat[1,6]) " \\" _newline

file write `hh2' "  Risk aversion in 2000 (standardized)  & " %04.3f (mean_stat[1,7]) " &  " %04.3f (sd_stat[1,7]) " & " %02.1f (min_stat[1,7]) " & " %02.1f (max_stat[1,7]) " & " (n_stat[1,7]) " \\" _newline
file write `hh2' "  Risk aversion in 2010 (standardized) & " %04.3f (mean_stat[1,8]) " &  " %04.3f (sd_stat[1,8]) " & " %02.1f (min_stat[1,8]) " & " %02.1f (max_stat[1,8]) " & " (n_stat[1,8]) " \\" _newline

file write `hh2' "  Number of success in 1985  & " %04.3f (mean_stat[1,9]) " &  " %04.3f (sd_stat[1,9]) " & " (min_stat[1,9]) " & " (max_stat[1,9]) " & " (n_stat[1,9]) " \\" _newline
file write `hh2' "  Number of success in 2000  & " %04.3f (mean_stat[1,10]) " &  " %04.3f (sd_stat[1,10]) " & " (min_stat[1,10]) " & " (max_stat[1,10]) " & " (n_stat[1,10]) " \\" _newline

file write `hh2' "  Hyperbolic discounting in 2000  & " %04.3f (mean_stat[1,11]) " &  " %04.3f (sd_stat[1,11]) " & " (min_stat[1,11]) " & " (max_stat[1,11]) " & " (n_stat[1,11]) " \\" _newline
file write `hh2' "  Hyperbolic discounting in 2010  & " %04.3f (mean_stat[1,12]) " &  " %04.3f (sd_stat[1,12]) " & " (min_stat[1,12]) " & " (max_stat[1,12]) " & " (n_stat[1,12]) " \\" _newline

file write `hh2' "  High discounting in 2000  & " %04.3f (mean_stat[1,13]) " &  " %04.3f (sd_stat[1,13]) " & " (min_stat[1,13]) " & " (max_stat[1,13]) " & " (n_stat[1,13]) " \\" _newline
file write `hh2' "  High discounting in 2010  & " %04.3f (mean_stat[1,14]) " &  " %04.3f (sd_stat[1,14]) " & " (min_stat[1,14]) " & " (max_stat[1,14]) " & " (n_stat[1,14]) " \\" _newline

file write `hh2' "  Years of education in 2000  & " %04.3f (mean_stat[1,15]) " &  " %04.3f (sd_stat[1,15]) " & " (min_stat[1,15]) " & " (max_stat[1,15]) " & " (n_stat[1,15]) " \\" _newline
file write `hh2' "  Head's age in 2000  & " %04.3f (mean_stat[1,16]) " &  " %04.3f (sd_stat[1,16]) " & " (min_stat[1,16]) " & " (max_stat[1,16]) " & " (n_stat[1,16]) " \\" _newline
file write `hh2' "  Head's age (40-70) in 2000  & " %04.3f (mean_stat[1,17]) " &  " %04.3f (sd_stat[1,17]) " & " (min_stat[1,17]) " & " (max_stat[1,17]) " & " (n_stat[1,17]) " \\" _newline
file write `hh2' "  Household size in 2000  & " %04.3f (mean_stat[1,18]) " &  " %04.3f (sd_stat[1,18]) " & " (min_stat[1,18]) " & " (max_stat[1,18]) " & " (n_stat[1,18]) " \\" _newline
file write `hh2' "  Farmland in 2000 & " %04.3f (mean_stat[1,19]) " &  " %04.3f (sd_stat[1,19]) " & " (min_stat[1,19]) " & " (max_stat[1,19]) " & " (n_stat[1,19]) " \\" _newline

file write `hh2' "\\\midrule" _newline
file write `hh2' "\end{tabular}" _newline
file write `hh2' "\begin{tablenotes}" _newline
file write `hh2' "\item Source: Authors' calculation using Saguling Household Survey 2000 and 2010. " _newline
file write `hh2' "\end{tablenotes}" _newline
file write `hh2' "\end{threeparttable}" _newline
file write `hh2' "}" _newline
file write `hh2' "\label{tab:addlabel}%" _newline
file write `hh2' "\end{table}" _newline

file write `hh2' "" _newline
file write `hh2' "" _newline
file write `hh2' "" _newline
file write `hh2' "" _newline

file close `hh2'
